package com.cfl.day1.ctrl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cfl.day1.dao.TestkeyMapper;
import com.cfl.day1.pojo.Testkey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
//查询testkey里面的所有学校
@RestController
public class TestCtrl {
    @Autowired
    private TestkeyMapper testkeyMapper;

    @RequestMapping("/")
    public void test(){
        System.out.println("成功接收请求");
    }

    @RequestMapping("/testKey")
    public void testKey(){
        //查询testkey里的所有信息
        List<Testkey> testkeys = testkeyMapper.selectList(null);
        for (Testkey k : testkeys){
            System.out.println(k);
        }

    }
    //添加testKey的信息
    @RequestMapping("/testKey2")
    public void testKey2(Testkey key){
        //添加一个testKey
        int insert = testkeyMapper.insert(key);
        System.out.println("成功插入数据:" + insert);
    }

    /**
//     * 分页配置
     */
    @RequestMapping("/testKey3")
    public void testKey3() {
        Page<Testkey> page = new  Page<>();
//        每页有5条
//        page.setSize(5l);
//        当前第2页
//        page.setCurrent(2l);
        //查询testkey里的所有信息,以分页的形式
//        QueryWrapper<Testkey> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("key1","z");
        Page<Testkey> testkeyPage = testkeyMapper.selectPage(page,null);
        List<Testkey> list = testkeyPage.getRecords();
        for (Testkey key : list){
            System.out.println(key);
        }
        System.out.println("-------------------------------------");
        System.err.println("当前第几页"+testkeyPage.getCurrent());
        System.err.println("每页多少条"+testkeyPage.getSize());
        System.err.println("总共的条数"+testkeyPage.getTotal());
    }
}

